#!/bin/bash
COMMON_PATH=$(realpath "${BASH_SOURCE[0]}")
COMMON_DIR=$(dirname "${COMMON_PATH}")
TEST_HOME=$(dirname "${COMMON_PATH}")
WORK_PATH=$(dirname "${TEST_HOME}")
#UTILS_DIR="${TEST_HOME}/Public/tools/utils"
 
#TODO
SUITE_REPO_LINK=""

QEMU=qemu
# Adaptation to the MAC platform
NPROC=$(nproc 2>/dev/null || sysctl -n hw.logicalcpu)
 
EXT_CODE=0
 
export PATH=${TEST_HOME}/Tools/bin:$PATH
 
check_result ()
{
    ret_code="$1"
    summary_message="$2"
    detail_err_file="$3"
    if [[ "${ret_code}" -eq 0 ]]; then
        echo -e "  ---- ${summary_message} success.\n"
    else
        echo "  ---- ${summary_message} failed!"
        [ -f "${detail_err_file}" ] && cat "${detail_err_file}"
        exit 1
    fi
}

check_cmd() {
    command -v "$1" > /dev/null 2>&1
}

say() {
    printf '[CPU-test] %s \n' "$1"
}

err() {
    say "$1" >&2
    exit 1
}

need_cmd()
{
    cmd="$1"
    if ! check_cmd "${cmd}"; then
        err "need '${cmd}' (command not found)"
    fi

}
#TODO git testsuite
 
get_user_ip()
{
    ipv4=$(hostname -I | awk -F' ' '{print $1}')
    user=$(whoami)
    echo "${user}@${ipv4}"
}
 
rm_mkdir()
{
    dir="$1"
    if [[ -z "${dir}" ]];then
        echo "need a folder name"
        return 1
    fi
   
    if [[ -d "${dir}"  ]];then
        rm -rf "${dir}"
    fi
   
    mkdir -p "${dir}"
}

rm_testcase()
{
    testcase_path="$1"
    untestlist="${@:2}"
    for FAIL_LIST in ${untestlist[@]}
    do
        cat "${FAIL_LIST}" | xargs rm -rf
    done
}

print_toolchain_path()
{
    toolchain_path="$1"
    echo "Please deploy toolchain under the path ${toolchain_path}\n"

}
